package com.itheima.mytest;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;

public class Test5 {
    public static void main(String[] args) throws IOException {
        StringBuilder sb=new StringBuilder();

        //读取数据
        FileReader fr=new FileReader("myio\\aa.txt");
        //吧读取到的数据存入sb
        int i;
        while ((i=fr.read())!=-1){
            sb.append((char)i);
        }
        //关流
        fr.close();
        System.out.println(sb);

        //排序并写入数据
        FileWriter fw=new FileWriter("myio\\aa.txt");

        Integer[] array = Arrays.stream(sb.toString().split("-"))
                .map(Integer::parseInt)
                .sorted()
                .toArray(Integer[]::new);
        for (int i1 = 0; i1 < array.length; i1++) {
            if(i1==array.length-1){
                fw.write(array[i1]+"");
                //System.out.println(array[i1]);
            }else{
                fw.write(array[i1]+"-");
                //System.out.print(array[i1]+"-");
            }
        }
        fw.close();
     }
}
